package com.qf.proxy.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.qf.proxy.entity.Info;
import com.qf.proxy.pubmed.entity.SpiderTbTrue;
import com.qf.proxy.pubmed.mapper.SpiderTbTrueMapper;
import com.qf.proxy.service.HandleData;
import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.net.URLDecoder;
import java.util.Arrays;
import java.util.List;

@RestController
@Slf4j
@RequestMapping("/index")
public class IndexController {

    @Resource
    HandleData handleData;
    @Resource
    SpiderTbTrueMapper spiderTbTrueMapper;


    @RequestMapping("/export")
    public Object export(String format, String ids) {
        log.info("format+++" + format);
        log.info("ids部分+++" + ids.substring(0, 6));
        String pubmedData = handleData.getPubmedData(format, ids);
        return pubmedData;
    }

    @SneakyThrows
    @PostMapping("/get-spider-tb-true")
    public Object findWosInfo(String table, String pmids) {
        // 远程查询tbtrue 数据用
        List<String> split = Arrays.asList(pmids.split(","));
        List<SpiderTbTrue> pm = spiderTbTrueMapper.selectList(new QueryWrapper<SpiderTbTrue>().in("PM", split));
        return pm;

    }


    //2021年1月11日10:31:17 用同一套逻辑 行不通 后续在看
    @RequestMapping("/export-param")
    public Object exportParam(String format, String param) {
        log.info("格式format+++" + format);
        log.info("param部分+++" + param);
        String pubmedData = handleData.getPubmedDataParam(format, URLDecoder.decode(param));
        return pubmedData;
    }

    //导出带有参数的 就是过滤用的
    @RequestMapping("/export-param-param")
    public Object exportParam(String format, String param, String sort, String filter) {
        log.info("格式format+++" + format);
        log.info("param部分+++" + param);
        log.info("filter部分+++" + filter);
        log.info("sort部分+++" + sort);
        String pubmedData = handleData.getPubmedDataParam(format, URLDecoder.decode(param), sort, filter);
        return pubmedData;
    }


    //2021年5月4日10:24:49 下载mesh词详情页相关信息的post 请求
    @RequestMapping("/downhtml")
    public Object downHtml(String param) {
        log.info("param部分+++" + param);
        String pubmedData = handleData.getHtml(param);
        return pubmedData;
    }

    //2021年6月5日11:25:34 下载mesh详情页
    @RequestMapping("/downMeshDetailhtml")
    public Object downMeshDetailHtml(String param) {
        log.info("param部分+++" + param);
        String pubmedData = handleData.getMeshDetailHtml(param);
        return pubmedData;
    }


    //mesh词检索 2021年5月11日17:26:30
    @RequestMapping("/search-mesh")
    public Object searchMesh(String key, Integer page, Integer limit, String sessionid, Integer total) {
        Info s = handleData.GetFirstMesh(key, page, limit, sessionid, total);
        return s;

    }


}
